﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Diagnostics;
using System.Windows;

namespace Xceed.Silverlight.DataGrid
{
  public sealed class ActivatingCellEditorEventArgs : EventArgs
  {
    #region Constructor

    internal ActivatingCellEditorEventArgs( Cell targetCell, FrameworkElement cellEditor )
    {
      if( targetCell == null )
        throw new ArgumentNullException( "targetCell" );

      if( cellEditor == null )
        throw new ArgumentNullException( "cellEditor" );

      if( ( targetCell.ParentRow == null ) || ( targetCell.ParentColumn == null ) )
        throw new ArgumentException( "The cell must have a parent row or column.", "targetCell" );

      m_targetCell = targetCell;
      m_cellEditor = cellEditor;
    }

    #endregion

    #region Cell Property

    public Cell Cell
    {
      get
      {
        return m_targetCell;
      }
    }

    private readonly Cell m_targetCell;

    #endregion

    #region Row Property

    public Row Row
    {
      get
      {
        var row = m_targetCell.ParentRow;

        Debug.Assert( row != null );

        return row;
      }
    }

    #endregion

    #region Column Property

    public Column Column
    {
      get
      {
        var column = m_targetCell.ParentColumn;

        Debug.Assert( column != null );

        return column;
      }
    }

    #endregion

    #region CellEditor Property

    public FrameworkElement CellEditor
    {
      get
      {
        return m_cellEditor;
      }
    }

    private readonly FrameworkElement m_cellEditor;

    #endregion

    #region DataItem Property

    public object DataItem
    {
      get
      {
        return m_targetCell.DataContext;
      }
    }

    #endregion

    #region DataPath Property

    public DataGridPath DataPath
    {
      get
      {
        if( m_dataPath == null )
        {
          m_dataPath = new DataGridPath( this.Row.Path );
        }

        return m_dataPath;
      }
    }

    private DataGridPath m_dataPath; //null

    #endregion
  }
}
